#ifndef MYBATTERY_H
#define MYBATTERY_H

#include <QWidget>
#include <QColor>

QT_BEGIN_NAMESPACE
namespace Ui { class MyBattery; }
QT_END_NAMESPACE

class MyBattery : public QWidget
{
    Q_OBJECT

public:
    MyBattery(QWidget *parent = nullptr);
    ~MyBattery();


    void setPowerLevel(int pow); //设置当前电量
    int powerLevel();
    void setWarnLevel (int warn); //设置电量低阈值
    int warnLevel ();

    virtual QSize sizeHint();//缺省大小

protected:
    void paintEvent(QPaintEvent * event) Q_DECL_OVERRIDE;

signals :
    void powerLevelChanged(int);

private:
    Ui::MyBattery *ui;

    QColor mColorBack = Qt::white;//背景颜色
    QColor mColorBorder = Qt::black; //电池边框颜色
    QColor mColorPower = Qt::green; //电量柱颜色
    QColor mColorWarning = Qt::red;//电量短缺时的颜色
    int mPowerLevel=60;//电量0-100
    int mWarnLevel=20; //电量低警示阈值

};
#endif // MYBATTERY_H
